package com.cj.webapp.account.controller;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.cj.webapp.account.pojo.ConstantParamter;
import com.cj.webapp.account.pojo.LoginEnterpriseDto;
import com.cj.webapp.account.service.AccountEnterpriseServiceImpl;
import com.cj.webapp.common.sign.SignVerifyHandle;
import com.cj.webapp.common.utils.MapDetail;
import com.cj.webapp.common.utils.UtilDatetime;

/**
 *
 * 企业会员开户
 * Created by dell on 2017/12/25.
 */

//@WebServlet(name = "addEnterprise",urlPatterns ={"/account"})
public class AccountEnterpriseServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	request.setCharacterEncoding("utf-8");
    	response.setContentType("text/html;charset=utf-8");
		//HttpSession session = request.getSession();
    	//response.setCharacterEncoding("utf-8");
        LoginEnterpriseDto enterpriseDto =new LoginEnterpriseDto();
        String custNm=request.getParameter("custNm");
        String idType=request.getParameter("idType");
        String idNo=request.getParameter("idNo");
        String platfmCustId =request.getParameter("platfmCustId");
        String channelCode=request.getParameter("channelCode");
        String email=request.getParameter("email");
        String province =request.getParameter("province");
        String city=request.getParameter("city");
        String role=request.getParameter("role");
        String wechatnum=request.getParameter("wechatnum");
        String unifiedCode=request.getParameter("unifiedCode");
        String orgNo =request.getParameter("orgNo");
        String businessLicense=request.getParameter("businessLicense");
        String taxNo =request.getParameter("taxNo");
        String cerditCode=request.getParameter("cerditCode");
        String legalNm= request.getParameter("legalNm");
        String lawIdType=request.getParameter("lawIdType");
		String lawIdNo=request.getParameter("lawIdNo");
        String contact =request.getParameter("contact");
        String registDt=request.getParameter("registDt");
        String compInfo =request.getParameter("compInfo");
        String compBankGround=request.getParameter("compBankGround");
        String compAddres=request.getParameter("compAddres");
        String inviteCd=request.getParameter("inviteCd");
        String nickNm=request.getParameter("nickNm");
        String bankLicense=request.getParameter("bankLicense");
        String bankAccNo=request.getParameter("bankAccNo");
        String bankNm=request.getParameter("bankNm");
        String bankCode=request.getParameter("bankCode");
		String phone =MapDetail.resMap.get("phone").toString();
		String bankBranchNm =request.getParameter("bankBranchNm");
		String bankProv =request.getParameter("bankProv");
		String bankCity =request.getParameter("bankCity");
		String bankCardOfMobile=request.getParameter("bankCardOfMobile");
		String cardType=request.getParameter("cardType");
		String remark =request.getParameter("remark");
		enterpriseDto.setCustNm(custNm);
		enterpriseDto.setIdType(idType);
		enterpriseDto.setIdNo(idNo);
		enterpriseDto.setPlatfmCustId(MapDetail.resMap.get("platfmCustId").toString());
		enterpriseDto.setChannelCode(channelCode);
		enterpriseDto.setEmail(email);
		enterpriseDto.setProvince(province);
		enterpriseDto.setCity(city);
		enterpriseDto.setRole(role);
		enterpriseDto.setWechatnm(wechatnum);
		enterpriseDto.setSource(MapDetail.resMap.get("source").toString());
		enterpriseDto.setUnifiedCode(unifiedCode);
		enterpriseDto.setOrgNo(orgNo);
		enterpriseDto.setBusinessLicense(businessLicense);
		enterpriseDto.setTaxNo(taxNo);
		enterpriseDto.setCerditCode(cerditCode);
		enterpriseDto.setLegalNm(legalNm);
		enterpriseDto.setLawIdType(lawIdType);
		enterpriseDto.setLawIdNo(lawIdNo);
		enterpriseDto.setContact(contact);
		enterpriseDto.setRegistDt(registDt);
		enterpriseDto.setCompInfo(compInfo);
		enterpriseDto.setCompBankGround(compBankGround);
		enterpriseDto.setCompAddres(compAddres);
		enterpriseDto.setInviteCd(inviteCd);
		enterpriseDto.setNickNm(nickNm);
		enterpriseDto.setBankLicense(bankLicense);
		enterpriseDto.setBankAccNo(bankAccNo);
		enterpriseDto.setBankNm(bankNm);
		enterpriseDto.setBankCode(bankCode);
		enterpriseDto.setPhone(phone);
		enterpriseDto.setBankBranchNm(bankBranchNm);
		enterpriseDto.setBankProv(bankProv);
		enterpriseDto.setBankCity(bankCity);
		enterpriseDto.setBankCardOfMobile(bankCardOfMobile);
		enterpriseDto.setCardType(cardType);
		enterpriseDto.setRemark(remark);

		SignVerifyHandle signVerifyHandle=new SignVerifyHandle();
		String s = signVerifyHandle.signData(ConstantParamter.VIP_NUM, JSON.toJSONString(enterpriseDto));

		SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmss");
		JSONObject jsonhead = new JSONObject(true);
		JSONObject jsonbody = new JSONObject(true);

		// head
		jsonhead.put("serviceName","ENTERPRISE_REGISTER");//接口名称
		jsonhead.put("vipNum",ConstantParamter.VIP_NUM);//会员编号（平台编号）
		jsonhead.put("requestDt", UtilDatetime.getDateString());//请求时间
		jsonhead.put("requestTm", UtilDatetime.getTimeString5());//请求时间
		jsonhead.put("requestNo", "110"+df.format(new Date()));//请求流水(贯穿整个请求返回)
		jsonhead.put("signData",s);
		jsonhead.put("sessionId",MapDetail.resMap.get("sessionId").toString());//sessionId
		jsonhead.put("source",MapDetail.resMap.get("source").toString());//source
		jsonhead.put("token",MapDetail.resMap.get("token").toString());
		jsonhead.put("version",ConstantParamter.VERSION_ID);
		jsonhead.put("rebackUrl",ConstantParamter.ACCOUNT_REBACK_Url);

		request.setAttribute("head",JSON.toJSONString(jsonhead));
		request.setAttribute("body",JSON.toJSONString(enterpriseDto));
		request.setAttribute("urlString",ConstantParamter.GATE_WAY_URL);

		request.getRequestDispatcher("/page/index/registerPost.jsp").forward(request,response);
    }
   
}
